package com.itheima.dubbo.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.QuestionsLock;
import com.itheima.dubbo.mapper.QuestionsLockMapper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 阿鹏
 * @date 2021/3/1 23:29
 */
@Service
public class QuestionsLockApiImpl implements QuestionsLockApi {

    @Autowired
    private QuestionsLockMapper lockMapper;

    @Override
    public void saveInitLock(QuestionsLock questionsLock) {
        lockMapper.insert(questionsLock);
    }

    @Override
    public void updateQuestionsLock(QuestionsLock questionsLock) {
        lockMapper.updateById(questionsLock);
    }

    @Override
    public QuestionsLock findByUserIdAndCid(Long userId, Long cid) {
        QueryWrapper<QuestionsLock> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", userId);
        wrapper.eq("cid", cid);
        return lockMapper.selectOne(wrapper);
    }
}
